package com.ruoyi.web.controller.zhhq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhhq.domain.Serviceorder;
import com.ruoyi.zhhq.service.IServiceorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修订单Controller
 * 
 * @author wlh
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/zhhq/serviceorder")
public class ServiceorderController extends BaseController
{
    @Autowired
    private IServiceorderService serviceorderService;

    /**
     * 查询维修订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:serviceorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(Serviceorder serviceorder)
    {
        startPage();
        List<Serviceorder> list = serviceorderService.selectServiceorderList(serviceorder);
        return getDataTable(list);
    }

    /**
     * 导出维修订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:serviceorder:export')")
    @Log(title = "维修订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Serviceorder serviceorder)
    {
        List<Serviceorder> list = serviceorderService.selectServiceorderList(serviceorder);
        ExcelUtil<Serviceorder> util = new ExcelUtil<Serviceorder>(Serviceorder.class);
        util.exportExcel(response, list, "维修订单数据");
    }

    /**
     * 获取维修订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhq:serviceorder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return AjaxResult.success(serviceorderService.selectServiceorderByOrderId(orderId));
    }

    /**
     * 新增维修订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:serviceorder:add')")
    @Log(title = "维修订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Serviceorder serviceorder)
    {
    	
    	System.out.print(serviceorder);
        return toAjax(serviceorderService.insertServiceorder(serviceorder));
    }

    /**
     * 修改维修订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:serviceorder:edit')")
    @Log(title = "维修订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Serviceorder serviceorder)
    {
        return toAjax(serviceorderService.updateServiceorder(serviceorder));
    }

    /**
     * 删除维修订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:serviceorder:remove')")
    @Log(title = "维修订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(serviceorderService.deleteServiceorderByOrderIds(orderIds));
    }
}
